﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CARMSBusiness;
using CARMSData.EntityClasses;

namespace CARMS.Controls
{
    public partial class GroupMessageControl : UserControlBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                LoadMessage();
            }
        }


        protected void gridList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //var jobID = ((DataRowView) e.Row.DataItem)["JobID"].ToString();
                //var jobEntity = new JobEntity(new Guid(jobID));

                //var lblJobNumber = e.Row.FindControl("lblJobNumber") as Label;
                //lblJobNumber.Text = jobEntity.RegistrationNumber;
                //lblJobNumber.ToolTip = lblJobNumber.Text;
            }
        }

        protected void gridList_OnRowCommand(object sender, GridViewCommandEventArgs e)
        {
            switch (e.CommandName)
            {

                case "ViewItem":
                    RediretResolveUrl(SiteUrls.Message.MessageDetail + "?GroupMessageID=" + e.CommandArgument.ToString());
                    break;
                case "DeleteItem":
                    //var boolSuccess = MessageBusiness.InActiveGroupMessage(new Guid(e.CommandArgument.ToString()));
                    //if (boolSuccess)
                    //{
                    //    LoadMessage();
                    //}
                    //else
                    //{
                    //    base.Alert("Delete Failed.");
                    //}
                    break;
                case "PickUp":
                    //var msgID = e.CommandArgument.ToString();
                    //var message = new GroupMessageEntity(new Guid(msgID));
                    //if (message.ActionUrl.Trim().Length > 0)
                    //{
                    //    RediretResolveUrl(message.ActionUrl);
                    //}
                    //else
                    //{
                    //    RediretResolveUrl(SiteUrls.Message.MessageDetail + "?GroupMessageID=" + msgID);
                    //}
                    break;
                    
            }
        }

        private void LoadMessage()
        {
            //var empId = SecurityBusiness.GetEmployeeIDByUserID(CurrentControlLoginUser.UserID);
            //if (empId.HasValue)
            //{
            //    var list = MessageBusiness.GetTopFiveGroupMessageList(empId.Value);
            //    gridList.DataSource = list;
            //    gridList.DataBind();

            //}
        }
    }
}